﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevComponents.DotNetBar;
using NHibernate;
using hbse.Entities;
using hbse.Service;

namespace hbse
{
    public partial class Usprintorder : UserControl
    {
        private TabItem newTab;
        private DevComponents.DotNetBar.TabControl tabControl2;
        private ISession session;
        private Users users;
        private UntilService untilService = new UntilService();

        public Usprintorder(DevComponents.DotNetBar.TabControl _tabControl2, TabItem _newTab, ISession _session, Users _users)
        {
            InitializeComponent();
            newTab = _newTab;
            tabControl2 = _tabControl2;
            session = _session;
            users = _users;
        }

        private void Usprintorder_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            List<hbse.DTO.OrderDTOS> orderDTOs = untilService.getOrdersBySaleOrder(txtsearch.Text.Trim(),session);
            if (orderDTOs.Count > 0)
            {
                dgvOrder.DataSource = orderDTOs;
                FormatdgvOrder();
            }
            else
            {
                dgvOrder.DataSource = null;
                FormatdgvOrder();
                 
            }
        }
        private void FormatdgvOrder()
        {
            if (dgvOrder.RowCount > 0)
            {
                dgvOrder.Columns["SaleOrder"].HeaderText = "SaleOrder";
                dgvOrder.Columns["ProductCode"].HeaderText = "ProductCode";

                dgvOrder.Columns["Id"].Visible = false;

            }
        }

        private void dgvOrder_CellMouseUp(object sender, DataGridViewCellMouseEventArgs e)
        {
            if (e.RowIndex == -1)
            {
                return;
            }
            hbse.DTO.OrderDTO orderDTO = untilService.getOrderBySaleOrder(dgvOrder.Rows[e.RowIndex].Cells["SaleOrder"].Value.ToString(), session);

            txtProductCode.Text = dgvOrder.Rows[e.RowIndex].Cells["ProductCode"].Value.ToString();
            txtSaleOrder.Text = orderDTO.SaleOrder;
            txtMRPNo.Text = orderDTO.MrpNo;
            txtQtyOrder.Text = orderDTO.QtyOrder;
            txtFGStock.Text = orderDTO.FGStock;
            txtQty.Text = orderDTO.Qty;
            txtPrice.Text = orderDTO.Price;
            txtBarcode.Text = orderDTO.Barcode;

        }
    }
}
